#include "CPaymentPlanEditDlg.h"

CPaymentPlanEditDlg::CPaymentPlanEditDlg(QWidget *parent)
    : QDialog(parent)
{
    ui.setupUi(this);
    setWindowFlag(Qt::FramelessWindowHint, true);
    setAttribute(Qt::WA_AlwaysStackOnTop, true);
}

void CPaymentPlanEditDlg::SetData(const zl::CPaymentPlan &plan)
{
    data_ = plan;
    ui.edt_alias->setText(plan.alias().c_str());
    ui.ck_isfree->setChecked(plan.is_free());

    ui.ck_need_prepaid->setChecked(plan.prepaid() == 1);
    ui.edt_prepaid_amount->setText(QString::number(plan.prepaid_amount()));

    ui.ck_need_overdue_charge->setChecked(plan.need_overdue_charge());
    ui.edt_trail_duration->setText(QString::number(plan.trail_duration()));
    ui.combo_billing_unit->setCurrentIndex(plan.billing_unit());
    ui.edt_billing_period->setText(QString::number(plan.billing_period()));
    ui.edt_billing_price->setText(QString::number(plan.billing_price()));
    ui.edt_max_period_count->setText(QString::number(plan.billing_caps()));
}

void CPaymentPlanEditDlg::on_btns_confirm_clicked()
{
    data_.set_alias(ui.edt_alias->text().toStdString());
    data_.set_free(ui.ck_isfree->isChecked());

    data_.set_prepaid(ui.ck_need_prepaid->isChecked() ? 1 : 0);
    data_.set_prepaid_amount(ui.edt_prepaid_amount->text().toInt());

    data_.set_need_overdue_charge(ui.ck_need_overdue_charge->isChecked());
    data_.set_billing_unit(ui.combo_billing_unit->currentIndex());
    data_.set_trail_duration(ui.edt_trail_duration->text().toInt());
    data_.set_billing_period(ui.edt_billing_period->text().toInt());
    data_.set_billing_price(ui.edt_billing_price->text().toInt());
    data_.set_billing_caps(ui.edt_max_period_count->text().toInt());

    accept();
}

void CPaymentPlanEditDlg::on_btnd_cancel_clicked()
{
    reject();
}
